package com.caac.core.dm;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.caac.core.config.ActionConf;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2004</p>
 * <p>Company: AgileCentury</p>
 * @author <a href="mailto:agile@agilecentury.com">AgileCentury</a>
 * @version 1.0
 */

public class Role extends BaseDm {
    private String id;
    private String roleName;
    private String roleDesc;
    private String notes;

    private Set users = new HashSet();
    private Set menus = new HashSet();

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getRoleDesc() {
        return roleDesc;
    }

    public void setRoleDesc(String roleDesc) {
        this.roleDesc = roleDesc;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Set getMenus() {
        return menus;
    }

    public void setMenus(Set menus) {
        this.menus = menus;
    }

    public void addMenu(Menu menu) {
        menus.add(menu);
    }

    public Set getUsers() {
        return users;
    }

    public String getId() {
        return id;
    }

    public void setUsers(Set users) {
        this.users = users;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void addUser(User user) {
        users.add(user);
    }

    protected int doHashCode() {
        return getHashCodeBuilder().append(roleName).toHashCode();
    }

    protected boolean doEquals(Object object) {
        Role other = (Role) object;
        return getEqualsBuilder().append(roleName, other.roleName).isEquals();
    }

    public boolean isAccessible(ActionConf actionConf) {
        for (Iterator it = menus.iterator(); it.hasNext(); ) {
            Menu menu = (Menu) it.next();
            if (menu.isAccessible(actionConf)) {
                return true;
            }
        }
        return false;
    }
}
